/**
 * @作者 伟子涵
 * @微信公号 搬砖暗夜码农
 * @开源项目 $ https://gitee.com/zhouwei5208888
 * @我的博客 $ http://itzhouwei.com
 * @创建时间 2023/12/20  10:54
 */
package com.itzhouwei.commerce.service;

import com.itzhouwei.commerce.event.UserRegisterEvent;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;


/**
 * @description:
 * @author：zw，微信：yingshengzw
 * @date: 2023/12/20  10:54 
 * @Copyright： 公众号：搬砖暗夜码农 | 博客：https://itzhouwei.com - 沉淀、分享、成长，让自己和他人都能有所收获！
 */
@Service
@Slf4j
public class EmailService implements ApplicationListener<UserRegisterEvent> {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Override
    //锦上添花，设置 @Async 注解，声明异步执行。毕竟实际场景下，发送邮件可能比较慢，又是非关键逻辑
    @Async // <3>
    public void onApplicationEvent(UserRegisterEvent event) { // <2>
        log.error("[onApplicationEvent][给用户({}) 发送邮件]", event.getUsername());
    }
}
